#!/usr/bin/python

import sys
import os
import re

class xtrabackup():

    __Excute = None

    def __init__(self):
        self.__Excute=os.system
        return

    def install(self,ips_worker):
        ip = ips_worker[0]
        self.__Excute("scp -r ./resource/cache/xtrabackup root@"+ip+":/opt/")
        self.__Excute("scp -r ./resource/cache/xtrabackup root@"+ip+":/opt/")
        self.__Excute("ssh "+ ip + " rpm -ivh /opt/xtrabackup/libev-4.15-3.el7.x86_64.rpm")
        self.__Excute("ssh "+ ip + " rpm -ivh /opt/xtrabackup/perl-DBD-MySQL-4.023-5.el7.x86_64.rpm")
        self.__Excute("ssh "+ ip + " rpm -ivh /opt/xtrabackup/percona-xtrabackup-2.3.2-1.el7.x86_64.rpm")
        return

    def backup(self,ips_worker,commonPass):
        ip = ips_worker[0]
        self.__Excute("ssh "+ ip + " chmod +x /opt/xtrabackup/backup.sh")
        self.__Excute("ssh "+ ip + " sh /opt/xtrabackup/backup.sh "+commonPass)
        return

    
if __name__ == "__main__":
    ips = ['172.22.29.177']
    B = xtrabackup()
    B.install(ips)
    B.backup(ips)